from stl_reader import *

class point_with_index(object):
    def __init__(self,x,y,id):
        self.x=x
        self.y=y
        self.index=id

def get_unique_array(file):
    mesh=read_stl(file)
    vertics=mesh.vertices
    array=np.asarray(vertics)
    unique_array=np.unique(array,axis=1)
    return unique_array

def get_bondary(array):
    min_x=np.min(array[0])
    min_y=np.min(array[1])
    min_z=np.min(array[2])
    max_x=np.max(array[0])
    max_y=np.max(array[1])
    max_z=np.max(array[2])
    return np.array([min_x,min_y,min_z,max_x,max_y,max_z])

def get_center(min_x,min_y,max_x,max_y):
    return np.array([(max_x-min_x)/2,(max_y-min_y)/2])

if __name__=="__main__":
    file="test_file1.STL"
    array=get_unique_array(file)
    boundary=get_bondary(array)
    # corner_1=np.array([boundary[0],boundary[1]])
    # corner_2=np.array([boundary[3],boundary[1]])
    min_x=np.min(array[:,0])
    min_y=np.min(array[:,1])
    min_z=np.min(array[:,2])
    max_x=np.max(array[:,0])
    max_y=np.max(array[:,1])
    max_z=np.max(array[:,2])
    corner_1 = np.array([min_y,min_z])
    corner_2 = np.array([min_y,max_z])
    corner_3 = np.array([max_y,max_z])
    corner_4 = np.array([max_y,min_z])
    center = get_center(min_y,min_z,max_y,max_z)
    cross_1=np.array([min_y,center[1]])
    cross_2=np.array([center[0],max_y])
    cross_3=np.array([max_y,center[1]])
    cross_4=np.array([center[1],min_z])
    #th feature list
    corner_array=np.array([[corner_1,corner_2],[corner_2,corner_3],[corner_3,corner_4],[corner_4,corner_1]])
    center_array=np.array([[cross_1,center],[cross_2,center],[cross_3,center],[cross_4,center]])



